package com.zzf.concurrent.example.design.pattern.guarded.suspension;

import com.zzf.concurrent.example.util.TimeUtil;

import java.util.Random;

/**
 * 客户端，负责推送任务到任务队列中
 * @author GaoFeng2017
 * @date 2019/9/8 9:48
 */
public class ClientThread<T> extends Thread {

    private T data;
    private RequestQueue<T> requestQueue;
    private Random random;

    public ClientThread(T data, RequestQueue<T> requestQueue) {
        this.data = data;
        this.requestQueue = requestQueue;
        this.random = new Random();
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            requestQueue.push(data);
            TimeUtil.sleep(random.nextInt(1000));
        }
    }
}
